/**
 *
 * author ThuanLT
 * Aug 20, 2014 10:14:19 PM
 *
 */
package vn.fsoft.gst.dao;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import vn.fsoft.gst.domain.Country;
@Repository
@SuppressWarnings("unchecked")
public class CountryDAOImpl implements CountryDAO {
	
	@Autowired 
	private SessionFactory sessionFactory;
	
	@Transactional
	public int addCountry(Country country) {
		Session session = sessionFactory.getCurrentSession();
		return (Integer) session.save(country);
		
	}
	public void updateCountry(Country newCountry) {
		sessionFactory.getCurrentSession().merge(newCountry);
	}
	public void deleteCountry(int countryID) {
		Country c = getCountryByID(countryID);
		sessionFactory.getCurrentSession().delete(c);
	}
	public List<Country> getListCountry() {
		Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Country.class);
		return criteria.list();
	}
	public Country getCountryByID(int countryID) {
		return (Country) sessionFactory.getCurrentSession().get(Country.class, countryID);
	}	
}
